const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentTab:0,
        dotation:false,
        use:false,
      
        navData:[
            {
                text: '已取消',
                status:0
            },
            {
                text: '预约中',
                status:1
            },
            {
                text: '排队中',
                status:2
            },
            {
                text: '清洗中',
                status:3
            },
            {
                text: '已完成',
                status:4
            },
           
           
        ],
        cur:1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        var status = options.status;
        console.log(status);
        if(status == undefined){
            status=1;
        }
        this.setData({
            currentTab:status 
        })
        var open=wx.getStorageSync('open');
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
        that.setData({
            platform:app.globalData.platform,    
            open:open,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.domain,
            uploadUrl:app.globalData.uploadUrl,
          })
    },
    switchNav(event){
        var cur = event.currentTarget.dataset.current;
        console.log(cur);  
        //每个tab选项宽度占1/5
        var singleNavWidth = this.data.width / 5;
        //tab选项居中                            
        this.setData({
            navScrollLeft: (cur - 2) * singleNavWidth
        })      
        if (this.data.currentTab == cur) {
            return false;
        } else {
          //  var status = this.data.navData[cur].status;
            this.setData({
                currentTab: cur
            })
            this.getList();
          
        }
    },
    switchTab(event){
        var cur = event.detail.current;
        var singleNavWidth = this.data.width / 5;
        var left = (cur - 2) * singleNavWidth;
        this.setData({
            currentTab: cur,
            navScrollLeft: left
        });
    },
    goBack:function(){
        wx.navigateBack();
      },
    goto:function(e){
      console.log(e);
      var url=e.currentTarget.dataset.url;
      var parent_id=wx.getStorageSync('parent_id');
      var index=e.currentTarget.dataset.index;
      if(url=="#"){

      }else if(url=='phone'){
        var phone=e.currentTarget.dataset.phone;
          wx.makePhoneCall({
            phoneNumber: phone,
          })
      }else{
          if(index=='index'){
              wx.reLaunch({
                  url: url,
                })
          }else{
              console.log(url);
              wx.navigateTo({
                  url: url,
                })
          }
     
      }
    // console.log(url);
  },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getList();
    },
  getList(){
      let that=this;
      let data=this.data;
      var open=wx.getStorageSync('open');
      var currentTab = data.currentTab;
      var navData = data.navData;
      console.log('currentTab'+currentTab);
      var status = navData[currentTab].status;
      wx.request({
        url: app.globalData.domain+'wechat/wash/getOrderList',
        data:{from:1,open_id:open.id,status:status},
        success:res=>{
          var data=res.data;
          console.log(data);
          that.setData({
            list:data.list,
            count:data.count
          })
        }
    })
  },
  updateOrder(e){
    var order_id = e.currentTarget.dataset.order_id;
    var car_id = e.currentTarget.dataset.car_id;
    var msg = e.currentTarget.dataset.msg;
    var status = e.currentTarget.dataset.status;
    var open = wx.getStorageSync('open');
    let that = this;
    wx.showModal({
      title: '系统提示',
      content: msg,
      complete: (res) => {
        if (res.cancel) {
          
        }
    
        if (res.confirm) {
          wx.request({
            url: app.globalData.domain+'wechat/wash/updateOrder',
            data:{from:1,open_id:open.id,order_id:order_id,car_id:car_id,status:status},
            success:res=>{
              var data=res.data;
              if(data.code==0){
                that.showModals(data.msg,data.url,data.index);
                that.getList();
              }else{
                that.showModals(data.msg,data.url,data.index);
              }
              //console.log(data);
            }
          })
        }
      }
    })
    
  },

showModals:function(msg,url,index){
  wx.showModal({
      title: '系统提示',
      content:msg,
      success:function(res){
        console.log(res)
         if(res.confirm){
          if(url){
            if(index == 'index'){
              wx.reLaunch({
                url: url,
              })
            }else{
              wx.navigateTo({
                url: url,
              })
            }
          }
         }
         if(res.cancel){

         }
      }
  })
},
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})